/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function wgutil(id_frawor){
    this.map;
    this.ti_puncol;
    this.size_marker = '0.3';
    this.lat;
    this.lng;
    this.edicion = false;
    this.id_area = "";
    this.area_polilinea;
    this.area_poligono;
    this.area_polilinea;
    this.markers = [];
    this.markers_creditos = [];
    this.poli_areas = [];
    this.punto_selec = "";
    this.t_p = [];
    this.infowindow = new google.maps.InfoWindow();
    this.pestado = false; //estado de la barra lateral derecha

    this.g_markers = []; //Arrays de todos los markers del maps
    this.g_labels_p = []; //Arrays de todos los labels del maps sobre los puntos
    this.g_labels = []; //Arrays de todos los labels del maps sobre las lineas
    this.g_lineas = []; //Arrays de todos las lineas del maps

    this.mo_ordena_cant = 'asc';
    this.mo_ordena_nomb = 'asc';
    this.l_MarkerClusterer = []; //Arrays de todos los clusterers del mapa
    this.est_gru;
    this.l_img; //lista de los json de las imagenes a mostrar en el slider
    this.imageSlider;
    this.img_selected;
    this.id_frawor = 0;
    this.marker_select = null;
    this.l_marker_select = [];
    this.drawing_manager;
    this.modo_seleccion = false;
    //    this.wgutil(id_frawor); //CONSTRUCTOR
    this.id_frawor = id_frawor;
    
    //    this.wgutil = function(id_frawor){
    //        console.log("objeto creado:"+this.id_frawor );
    //    };
    
    this.navIE8 = navigator.userAgent.indexOf("MSIE 7");
    
    this.initialize = function(ti_geovis,nu_geoace){
        console.log("iniciando initialize:"+ti_geovis+":::"+nu_geoace);
        var latlng = new google.maps.LatLng("-12.16263412211394", "-76.94184830700681");
        var maptype;
        if (ti_geovis == 'M') {
            maptype = google.maps.MapTypeId.ROADMAP;
        } else if (ti_geovis == 'S') {
            maptype = google.maps.MapTypeId.HYBRID;
        }
        var Options = {
            zoom: nu_geoace,
            //            zoom: 8,
            center: latlng,
            mapTypeId: maptype,
            //            mapTypeId: google.maps.MapTypeId.ROADMAP,
            panControl: false,
            zoomControl: true,
            zoomControlOptions: {
                position: google.maps.ControlPosition.RIGHT_BOTTOM,
                style: google.maps.ZoomControlStyle.SMALL
            },
            scaleControl: false,
            mapTypeControl: false,
            mapTypeControlOptions: {
                style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
                position: google.maps.ControlPosition.RIGHT_TOP
            }
        };
        this.lat = latlng.lat();
        this.lng = latlng.lng();
        console.log("iniciando initialize:-->"+document.getElementById("map_canvas"));
        this.map = new google.maps.Map(document.getElementById("map_canvas"), Options);
        console.log("iniciando initialize: Mapa creado");
        this.map.controls[google.maps.ControlPosition.TOP_CENTER].push(document.getElementById("main_head"));
        this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].push(document.getElementById("point_description"));
        this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(document.getElementById("layer_control"));
        this.map.controls[google.maps.ControlPosition.TOP_RIGHT].push(document.getElementById("wg_main_opt"));
        console.log("this.map:"+this.map)
        console.log("this.map:"+this.map.getZoom());
        google.maps.event.addListener(this.map, 'zoom_changed', this.mzoon_changed);
        console.log("B->this.map:"+this.map)
        this.drawing_manager = new google.maps.drawing.DrawingManager({
            drawingMode: google.maps.drawing.OverlayType.RECTANGLE,
            drawingControl: false,
            rectangleOptions: {
                strokeWeight: 1
            }
        });
    }
        
    this.p_cargapuntos =function(jsonPuntos) {
        var json = JSON.parse(jsonPuntos);
        for (var i = 0; i < json.length; i++) {
            this.g_markers[this.g_markers.length] = new google.maps.Marker({
                id: json[i].id_pungeo,
                position: new google.maps.LatLng(json[i].nu_geolat, json[i].nu_geolon),
                map: null,
                //                    map: this.map,
                draggable: false
            });
            this.t_p[this.t_p.length] = new google.maps.LatLng(json[i].nu_geolat, json[i].nu_geolon);
            //              google.maps.event.addListener(punto, 'click', infopunto);
            google.maps.event.addListener(this.g_markers[this.g_markers.length - 1], 'click', this.ponclick);
            //              google.maps.event.addListener(g_markers[g_markers.length - 1], 'mouseover', pmouseover);
            //              google.maps.event.addListener(g_markers[g_markers.length - 1], 'mouseout', pmouseout);
            //              google.maps.event.addListener(g_markers[g_markers.length - 1], 'dblclick', pdblclick);
            google.maps.event.addListener(this.map, 'click', this.control_descripcion);
            google.maps.event.addListener(this.infowindow, 'closeclick', function(event) {
                //                  marker_select.setIcon("../img/gps/markers/" + marker_select.no_colore + "_" + size_marker + ".png");
                wgutil.marker_select.setAnimation(null);
            });
        }
    }

    this.p_cambiarpuntos = function(l_cfg, url_img, color, nu_geocapval) {
        var l_markers_agrup = [];
        for (var i = 0; i < this.g_markers.length; i++) {
            var marker = this.g_markers[i];
            var cfg = "";
            for (var j = 0; j < l_cfg.length; j++) {
                if (marker.id == l_cfg[j].id_pungeo) {
                    cfg = l_cfg[j];
                    break;
                }
            }

            if (cfg != "") {
                l_markers_agrup[l_markers_agrup.length] = marker;
                marker.setIcon(url_img);
                var js = "";
                try {
                    js = JSON.parse(cfg.no_pundes);
                } catch (e) {}

                marker.no_coment = cfg.no_pundes;
                marker.co_expedi = js.Expediente;
                marker.no_colore = color;
                marker.nu_geocapval = nu_geocapval;
                marker.setMap(this.map);
            }
        }
        return l_markers_agrup;
    }

    this.p_ocultarpuntos = function(l_cfg) {
        for (var i = 0; i < this.g_markers.length; i++) {
            var marker = this.g_markers[i];
            var cfg = "";
            for (var j = 0; j < l_cfg.length; j++) {
                if (marker.id == l_cfg[j].id_pungeo) {
                    cfg = l_cfg[j];
                    break;
                }
            }
            if (cfg != "") {
                marker.setMap(null);
            }
        }
    }


    this.limpiar_markers = function() {
        for (var i = 0; i < this.g_markers.length; i++) {
            this.g_markers[i].setMap(null);
        }
    }
    
    /*
     *FUNCION QUE GENERA EL PUNTO CENTRAL DE TODOS LOS PUNTOS
     **/
    this.punto_central = function () {
        var bounds = new google.maps.LatLngBounds();
        for (var i = 0; i < this.t_p.length; i++) {
            bounds.extend(this.t_p[i]);
        }
        var center_tot = bounds.getCenter();
        this.map.setOptions({
            center: center_tot
        });
    }
    
    /*
 *FUNCION QUE GENERA EL PUNTO MEDIO DE DOS LOS PUNTOS
 **/
    this.punto_medio = function(p_i, p_f) {
        var bounds = new google.maps.LatLngBounds();
        bounds.extend(p_i);
        bounds.extend(p_f);
        var p_m = bounds.getCenter();
        return p_m;
    }

    this.ponclick = function(event) {
        if (wgutil.modo_seleccion) {
            var existe = false;
            for (var i = 0; i < wgutil.l_marker_select.length; i++) {
                if (wgutil.l_marker_select[i].id == this.id) {
                    existe = true;
                    wgutil.l_marker_select.splice(i, 1);
                    this.setAnimation(null);
                    break;
                }
            }
            if (!existe) {
                wgutil.l_marker_select[wgutil.l_marker_select.length] = this;
                this.setAnimation(google.maps.Animation.BOUNCE);
            }
            document.getElementById("puntos_seleccionados").innerHTML = wgutil.l_marker_select.length;
        } else {
            var tip = document.getElementById("cbo_tidet").value;
            if (wgutil.marker_select != null) {
                wgutil.marker_select.setIcon("../img/gps/markers/" + wgutil.marker_select.no_colore + "_" + wgutil.size_marker + ".png");
                wgutil.marker_select.setAnimation(null);
                this.setAnimation(google.maps.Animation.BOUNCE);
                wgutil.marker_select = this;
            } else {
                wgutil.marker_select = this;
                this.setAnimation(google.maps.Animation.BOUNCE);
            }

            if (tip == 'L') {
                var table = document.getElementById("table_detalle_punto1");
                table.innerHTML = "";
                var html = "";
                var j = JSON.parse(this.no_coment);
                for (name in j) {
                    if (j.hasOwnProperty(name)) {
                        html += "<tr><td>" + name + "</td><td>" + j[name] + "</td></tr>";
                    }
                }
                table.innerHTML = "<table class='table_info' align='center'>"+ html +"</table>"
                
                //                        document.getElementById("expediente").innerHTML = JSON.parse(this.no_coment).html;
                //                        document.getElementById("cliente").innerHTML = JSON.parse(this.no_coment).Cliente;
                //                        document.getElementById("imagenes").innerHTML = JSON.parse(this.no_coment).imagenes;
                document.getElementById("point_description").style.display = "block";
                if (this.filtros == undefined) {
                    var txt = gettextfromurl(new getXMLObject(), "../wgp?xact=7&id_frawor=" + wgutil.id_frawor + "&id_pungeo=" + this.id);
                    var json = JSON.parse(txt);
                    this.filtros = txt;
                    var html = "";
                    for (var i = 0; i < json.length; i++) {
                        html += "<tr><td>" + json[i].filtro + "</td><td>" + json[i].agrupamiento + "</td></tr>";
                    }
                    document.getElementById("table_filtro_punto1").innerHTML = "<table class='table_info' align='center'>"+ html +"</table>"
                    
                    
                } else {
                    var json = JSON.parse(this.filtros);
                    var html = "";
                    for (var i = 0; i < json.length; i++) {
                        html += "<tr><td>" + json[i].filtro + "</td><td>" + json[i].agrupamiento + "</td></tr>";
                    }
                    document.getElementById("table_filtro_punto1").innerHTML = "<table class='table_info' align='center'>"+ html +"</table>"
                    

                }
            } else if (tip == 'I') {
                wgutil.infowindow.setContent(" ");
                var table = document.getElementById("table_detalle_punto1");
                table.innerHTML = "";
                var html = "";
                var j = JSON.parse(this.no_coment);
                for (name in j) {
                    if (j.hasOwnProperty(name)) {
                        html += "<tr><td>" + name + "</td><td>" + j[name] + "</td></tr>";
                        
                    }
                }
                table.innerHTML = "<table class='table_info' align='center'>"+ html +"</table>"
                //                        document.getElementById("expediente").innerHTML = JSON.parse(this.no_coment).html;
                //                        document.getElementById("cliente").innerHTML = JSON.parse(this.no_coment).Cliente;
                if (this.filtros == undefined) {
                    var txt = gettextfromurl(new getXMLObject(), "../wgp?xact=7&id_frawor=" + wgutil.id_frawor + "&id_pungeo=" + this.id);
                    var json = JSON.parse(txt);
                    this.filtros = txt;
                    var html = "";
                    for (var i = 0; i < json.length; i++) {
                        html += "<tr><td>" + json[i].filtro + "</td><td>" + json[i].agrupamiento + "</td></tr>";
                    }
                    document.getElementById("table_filtro_punto1").innerHTML = "<table class='table_info' align='center'>"+ html +"</table>"
                    //                    document.getElementById("table_filtro_punto").innerHTML = html;
                    wgutil.infowindow.setContent(document.getElementById("table_detalle").cloneNode(true));
                    wgutil.infowindow.setPosition(event.latLng);
                    wgutil.infowindow.open(wgutil.map);
                } else {
                    var json = JSON.parse(this.filtros);
                    var html = "";
                    for (var i = 0; i < json.length; i++) {
                        html += "<tr><td>" + json[i].filtro + "</td><td>" + json[i].agrupamiento + "</td></tr>";
                    }
                    document.getElementById("table_filtro_punto1").innerHTML = "<table class='table_info' align='center'>"+ html +"</table>"
                    //                    document.getElementById("table_filtro_punto").innerHTML = html;
                    wgutil.infowindow.setContent(document.getElementById("table_detalle").cloneNode(true));
                    wgutil.infowindow.setPosition(event.latLng);
                    wgutil.infowindow.open(wgutil.map);
                }
            }
        }
    }
    
    this.pdblclick = function(event) {
        wgutil.infowindow.setContent(" ");
        var html = "<center>";
        var js = getjsonfromurl(new getXMLObject(), "../wgp?xact=5&co_expedi=" + this.co_expedi);
        if (js.length == 0){
            wgutil.infowindow.open(null);
        }else {
            for (var i = 0; i < js.length; i++) {
                html = html + "<img src=\"../wgp?xact=6&id_arcadj=" + js[i].id_arcadj + "\" onclick=\"wgutil.mostrar_imagenes(" + i + ")\" style=\"cursor:pointer\">&nbsp"
            }
            this.l_img = js;
            console.log("html: " + html);
            wgutil.infowindow.setContent(html);
            wgutil.infowindow.setPosition(event.latLng);
            wgutil.infowindow.open(wgutil.map);
        }

    }

    this.mostrar_imagenes = function(index) {
        document.getElementById("modalDialogPageBackground").style.display = "block";
        document.getElementById("slider").style.display = "block";
        this.img_selected = index;
        var html = "";
        for (var i = 0; i < l_img.length; i++) {
            var display = "none";
            if (i == index) {
                display = "block"
            }
            html = html + "<img id=\"img_" + this.l_img[i].id_arcadj + "\" src=\"http://wf1.accesocrediticio.com/acceso/workflow2/view_load4.jsp?tipo=T&file=" + l_img[i].id_arcadj + "\" style=\"display:" + display + ";max-width:100%;max-height:100%\" >"
        }
        document.getElementById("img_container").innerHTML = html;
    }

    this.pmouseover = function(event) {
        document.getElementById("expediente").innerHTML = JSON.parse(this.no_coment).html;
        document.getElementById("cliente").innerHTML = JSON.parse(this.no_coment).Cliente;
        document.getElementById("point_description").style.display = "block";
        console.log("filtros: " + this.filtros);
        if (this.filtros == undefined) {
            var txt = gettextfromurl(new getXMLObject(), "../wgp?xact=7&id_frawor=" + this.id_frawor + "&id_pungeo=" + this.id);
            var json = JSON.parse(txt);
            console.log("filtros: " + json + " - length: " + json.length);
            this.filtros = txt;
            var html = "";
            for (var i = 0; i < json.length; i++) {
                html += "<tr><td>" + json[i].filtro + "</td><td>" + json[i].agrupamiento + "</td></tr>";
            }
            document.getElementById("table_filtro_punto").innerHTML = html;
        } else {
            var json = JSON.parse(this.filtros);
            var html = "";
            for (var i = 0; i < json.length; i++) {
                html += "<tr><td>" + json[i].filtro + "</td><td>" + json[i].agrupamiento + "</td></tr>";
            }
            document.getElementById("table_filtro_punto").innerHTML = html;
        }
    }

    this.pmouseout = function(event) {
        if (!pestado) {
            document.getElementById("point_description").style.display = "none";
        }
    }

    this.g_markers_change_size = function(new_size) {
        
        for (var i = 0; i < this.g_markers.length; i++) {
            //                    if(marker_select != g_markers[i])
            //                    {
            this.g_markers[i].setIcon("../img/gps/markers/" + this.g_markers[i].no_colore + "_" + new_size + ".png");
        //                    }
        }
        
    }

    this.cambio_capa = function(node) {
        var js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&co_filtro=" + node.options[node.selectedIndex].value);
        document.getElementById("layer_control").innerHTML = js;
        for (var c = 0; c < this.l_MarkerClusterer.length; c++) {
            this.l_MarkerClusterer[c].cluster.clearMarkers();
        }
        this.limpiar_markers();
        this.mostrar_all_markers(this.id_frawor);
    }

    this.ordenarAgrupamientos = function(tipo) {
        var js;
        if (tipo == "nombre") {
            js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&ti_ordena=" + tipo + "&mo_ordena=" + this.mo_ordena_nomb);
            if (this.mo_ordena_nomb == 'asc')
                this.mo_ordena_nomb = 'desc'
            else if (this.mo_ordena_nomb == 'desc')
                this.mo_ordena_nomb = 'asc'
        } else if (tipo == "cantidad") {
            js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&ti_ordena=" + tipo + "&mo_ordena=" + this.mo_ordena_cant);
            if (this.mo_ordena_cant == 'asc')
                this.mo_ordena_cant = 'desc'
            else if (this.mo_ordena_cant = 'desc')
                this.mo_ordena_cant = 'asc'
        }
        document.getElementById("layer_control").innerHTML = js;
    }


    this.limpiar_clusters = function() {
        for (var c = 0; c < this.l_MarkerClusterer.length; c++) {
            this.l_MarkerClusterer[c].cluster.clearMarkers();
        }
    }
    
    this.filtrar_agrupamientos = function() {
        this.limpiar_markers();
        this.limpiar_clusters();
        this.l_MarkerClusterer = [];
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&filtrar=true");
        document.getElementById("layer_control").innerHTML = js;
        this.mostrar_all_markers(this.id_frawor);
    }

    this.eliminar_filtro = function(nu_geocap) {
        this.limpiar_clusters();
        l_MarkerClusterer = [];
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&co_filtro_eliminar=" + nu_geocap);
        document.getElementById("layer_control").innerHTML = js;
        this.mostrar_all_markers(id_frawor);
    }

    this.editar_filtro = function(nu_geocap) {
        //                limpiar_clusters();
        //                l_MarkerClusterer = [];
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&co_filtro_editar=" + nu_geocap);
        document.getElementById("layer_control").innerHTML = js;
    //                mostrar_all_markers(id_frawor);
    }

    this.terminar_edicion = function() {
        this.limpiar_markers();
        this.limpiar_clusters();
        this.l_MarkerClusterer = [];
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&terminar_edicion=true");
        document.getElementById("layer_control").innerHTML = js;
        this.mostrar_all_markers();
    }

    this.crear_portafolio = function() {
        this.limpiar_clusters();
        this.l_MarkerClusterer = [];
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&portafolio=true");
        document.getElementById("layer_control").innerHTML = js;
        this.mostrar_all_markers();
    }

    this.eliminar_portafolio = function() {
        this.limpiar_clusters();
        this.l_MarkerClusterer = [];
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&portafolio=false");
        document.getElementById("layer_control").innerHTML = js;
        this.mostrar_all_markers();
    }

    this.cambio_puntos = function (tipo, color, nu_geocapval, node, il_cambiaimg, edicion) {
        //        alert("node.id : "+node.id);
        if (edicion) {
            if (tipo == "click") {
                if (node.id == 0)
                    node.id = 1;
                else if (node.id > 0)
                    node.id = 0;

                getjsonfromurl(new getXMLObject(), "../wgp?xact=3&id_frawor=" + id_frawor + "&nu_geocapval=" + nu_geocapval + "&il_select=" + node.id);
                if (node.id > 0) {
                    node.getElementsByTagName("img")[0].src = "../img/gps/eye_open.png";
                    try {
                        node.getParent().getParent().style.color = "black";
                    } catch (e) {
                        node.parentNode.parentNode.style.color = "black";
                    }
                } else if (node.id == 0) {
                    node.getElementsByTagName("img")[0].src = "../img/gps/eye_cancel.png";
                    try {
                        node.getParent().getParent().style.color = "";
                    } catch (e) {
                        node.parentNode.parentNode.style.color = "";
                    }
                }
            } else if (tipo == "dbclick") {
                if(wgutil.navIE8 == -1) var eyes = document.getElementById("tb_agrupamientos").getElementsByClassName("eye");
                else var eyes = getElementsByClassName("eye", "*", document.getElementById("tb_agrupamientos"));
                for (var i = 0; i < eyes.length; i++) {
                    if (eyes[i].id == 1) {
                        cambio_puntos('click', eyes[i].getAttribute("ti_puncol"), eyes[i].getAttribute("nu_geocapval"), eyes[i], true, true);
                    }
                }

                if (node.id == 0) {
                    node.onclick();
                }
            }
        } else {
            this.ti_puncol = color;
            var url_img = "http://chart.apis.google.com/chart?chst=d_map_spin&chld=" + this.size_marker + "|0|" + color + "|8|_|";

            var img = new Image();
            img.onload = function() {
                console.log("si existe");
                url_img = "../img/gps/markers/" + color + "_" + wgutil.size_marker + ".png"
                wgutil.cambio_puntos_cont(tipo, nu_geocapval, node, url_img, color, il_cambiaimg);
            };

            img.onerror = function() {
                console.log("no existe: " + color + "_" + wgutil.size_marker + ".png");
                gettextfromurl_asinc(new getXMLObject(), "../wgp?xact=4&size=" + wgutil.size_marker + "&color=" + color);
                //mostrar la imagen de google
                wgutil.cambio_puntos_cont(tipo, nu_geocapval, node, url_img, color, il_cambiaimg);
            };
            img.src = "../img/gps/markers/" + color + "_" + this.size_marker + ".png";
        }
    }
    
    this.img_onload = function(tipo, color, nu_geocapval, node, il_cambiaimg, edicion,url_img){
        console.log("si existe");
        url_img = "../img/gps/markers/" + color + "_" + this.size_marker + ".png";
        console.log(">>url_img:"+url_img);
        wgutil.cambio_puntos_cont(tipo, node, url_img, color, il_cambiaimg);
    }
    
    this.img_onerror = function(tipo, color, nu_geocapval, node, il_cambiaimg, edicion,url_img){
        console.log("no existe: " + color + "_" + this.size_marker + ".png");
        gettextfromurl_asinc(new getXMLObject(), "../wgp?xact=4&size=" + this.size_marker + "&color=" + color);
        //mostrar la imagen de google
        wgutil.cambio_puntos_cont(tipo, node, url_img, color, il_cambiaimg);
    }

    this.cambio_puntos_direct = function(tipo, color, nu_geocapval, node, il_cambiaimg) {
        var url_img = "../img/gps/markers/" + color + "_" + this.size_marker + ".png";
        wgutil.cambio_puntos_cont(tipo, nu_geocapval, node, url_img, color, il_cambiaimg);
    }


    this.cambio_puntos_cont = function(tipo, nu_geocapval, node, url_img, color, il_cambiaimg) {
        var l_cfg;
        if (tipo == "click") {
            if (il_cambiaimg) {
                if (node.id == 0)
                    node.id = 1;
                else if (node.id > 0)
                    node.id = 0;
            }
            if (il_cambiaimg)
                l_cfg = getjsonfromurl(new getXMLObject(), "../wgp?xact=3&id_frawor=" + id_frawor + "&nu_geocapval=" + nu_geocapval + "&il_select=" + node.id);
            else
                l_cfg = getjsonfromurl(new getXMLObject(), "../wgp?xact=9&id_frawor=" + id_frawor + "&nu_geocapval=" + nu_geocapval);
            console.log("cambio_puntos_cont-url: " + url_img);

            if (node.id > 0) {
                var l_marker_agrup = wgutil.p_cambiarpuntos(l_cfg, url_img, color, nu_geocapval);

                if (this.est_gru == true && l_marker_agrup.length > 0) {
                    var clustererStyles = [{
                        url: '../cluster?color=' + l_marker_agrup[0].no_colore, 
                        textColor: '#808080', 
                        textSize: 15, 
                        height: 65, 
                        width: 66
                    },

                    {
                        url: '../cluster?color=' + l_marker_agrup[0].no_colore, 
                        textColor: '#808080', 
                        textSize: 15, 
                        height: 65, 
                        width: 66
                    },

                    {
                        url: '../cluster?color=' + l_marker_agrup[0].no_colore, 
                        textColor: '#808080', 
                        textSize: 15, 
                        height: 65, 
                        width: 66
                    }];

                    var options = {
                        styles: clustererStyles
                    }

                    var mc = new MarkerClusterer(wgutil.map, [], options);
                    mc.addMarkers(l_marker_agrup);
                    var js = {
                        "id": nu_geocapval, 
                        "cluster": mc
                    };
                    var est = false;
                    for (var i = 0; i < this.l_MarkerClusterer.length; i++) {
                        if (this.l_MarkerClusterer[i].id == js.id) {
                            this.l_MarkerClusterer[i].cluster = js.cluster;
                            est = true;
                        }
                    }
                    if (!est) {
                        this.l_MarkerClusterer[l_MarkerClusterer.length] = js;
                    }
                }
                if (il_cambiaimg) {
                    node.getElementsByTagName("img")[0].src = "../img/gps/eye_open.png";
                    try {
                        node.getParent().getParent().style.color = "black";
                    } catch (e) {
                        node.parentNode.parentNode.style.color = "black";
                    }
                }
            } else if (node.id == 0) {
                //ocultar puntos
                wgutil.p_ocultarpuntos(l_cfg);

                for (var c = 0; c < this.l_MarkerClusterer.length; c++) {
                    if (nu_geocapval == this.l_MarkerClusterer[c].id) {
                        this.l_MarkerClusterer[c].cluster.clearMarkers();
                    }
                }

                if (il_cambiaimg) {
                    node.getElementsByTagName("img")[0].src = "../img/gps/eye_cancel.png";
                    try {
                        node.getParent().getParent().style.color = "";
                    } catch (e) {
                        node.parentNode.parentNode.style.color = "";
                    }
                }
            }
            wgutil.actualizar_puntos_visibles();
        } else if (tipo == "dbclick") {
            if(wgutil.navIE8 == -1) var eyes = document.getElementsByClassName("eye");
            else var eyes = getElementsByClassName("eye");
            wgutil.deseleccionar_all_markers(id_frawor);
            if (node.id == 0) {
                node.onclick();
            }
        }
    }

    this.deseleccionar_all_markers =function() {
        if(wgutil.navIE8 == -1) var eyes = document.getElementById("tb_agrupamientos").getElementsByClassName("eye");
        else var eyes = getElementsByClassName("eye", "*", document.getElementById("tb_agrupamientos"));
        for (var i = 0; i < eyes.length; i++) {
            if (eyes[i].id == 1) {
                console.log("   deseleccionando: " + eyes[i].getAttribute("nu_geocapval"))
                this.cambio_puntos_direct('click', eyes[i].getAttribute("ti_puncol"), eyes[i].getAttribute("nu_geocapval"), eyes[i], true);
            }
        }
    }

    this.mostrar_all_markers = function() {
        if(wgutil.navIE8 == -1) var eyes = document.getElementById("tb_agrupamientos").getElementsByClassName("eye");
        else var eyes = getElementsByClassName("eye", "*", document.getElementById("tb_agrupamientos"));
        for (var i = 0; i < eyes.length; i++) {
            if (eyes[i].id == 1) {
                this.cambio_puntos('click', eyes[i].getAttribute("ti_puncol"), eyes[i].getAttribute("nu_geocapval"), eyes[i], false, false);
            }
        }
    }

    this.option_control = function(tit, cont, opt){
        var lado = document.getElementById(opt).className;
        var estilo = document.getElementById(cont).style.display;
        if (lado == "opt_left"){
            if (estilo == "none"){
                document.getElementById(cont).style.display = "block";
                document.getElementById(tit).style.display = "block";
                document.getElementById(opt).style.left = '310px';
                document.getElementById('il_icoopt').src = "../img/gps/min_layer.png";
            }else{
                document.getElementById(cont).style.display = "none";
                document.getElementById(tit).style.display = "none";
                document.getElementById(opt).style.left = '0px';
                document.getElementById('il_icoopt').src = "../img/gps/max_layer.png";
            }
        } else if (lado == "opt_right"){
            if (estilo == "none"){
                document.getElementById(cont).style.display = "block";
                document.getElementById(tit).style.display = "block";
                document.getElementById(opt).style.right = '227px';
            }else{
                document.getElementById(cont).style.display = "none";
                document.getElementById(tit).style.display = "none";
                document.getElementById(opt).style.right = '0px';
            }
        }
    }

    this.tipo_mapa = function(tip) {
        if (tip == 'M') {
            this.map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
            document.getElementById("chk_lin").disabled = true;
            document.getElementById("chk_lin").checked = true;
        } else if (tip == 'S') {
            this.map.setMapTypeId(google.maps.MapTypeId.HYBRID);
            document.getElementById("chk_lin").disabled = false;
        }
    }

    this.cambia_lineas = function(chk) {
        if (chk.checked == false && this.map.getMapTypeId() == "hybrid") {
            this.map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
        } else if (this.map.getMapTypeId() == "satellite") {
            this.map.setMapTypeId(google.maps.MapTypeId.HYBRID);
        }
    }

    this.usa_grupos = function(chk) {
        if (chk.checked) {
            wgutil.est_gru = true;
            var l_general = [];
            for (var i = 0; i < wgutil.g_markers.length; i++) {
                if (wgutil.g_markers[i].getMap() != null) {
                    var id = wgutil.g_markers[i].nu_geocapval;
                    var est = false;
                    for (var j = 0; j < l_general.length; j++) {
                        var l = l_general[j];
                        if (l[0].id == id) {
                            var json = {
                                "id": id, 
                                "marker": wgutil.g_markers[i]
                            };
                            l[l.length] = json;
                            est = true;
                        }
                    }
                    if (est == false) {
                        var l_temp = [];
                        var json = {
                            "id": id, 
                            "marker": wgutil.g_markers[i]
                        };
                        l_temp[l_temp.length] = json;
                        l_general[l_general.length] = l_temp;
                    }
                }
            }

            for (var i = 0; i < l_general.length; i++) {
                var l_agr = l_general[i];
                var l_marks = [];
                var id;
                for (var j = 0; j < l_agr.length; j++) {
                    l_marks[l_marks.length] = l_agr[j].marker;
                }
                var clustererStyles = [{
                    url: '../cluster?color=' + l_marks[0].no_colore, 
                    textColor: '#808080', 
                    textSize: 15, 
                    height: 65, 
                    width: 66
                },

                {
                    url: '../cluster?color=' + l_marks[0].no_colore, 
                    textColor: '#808080', 
                    textSize: 15, 
                    height: 65, 
                    width: 66
                },

                {
                    url: '../cluster?color=' + l_marks[0].no_colore, 
                    textColor: '#808080', 
                    textSize: 15, 
                    height: 65, 
                    width: 66
                }];
                var options = {
                    styles: clustererStyles
                }

                var mc = new MarkerClusterer(wgutil.map, [], options);
                mc.addMarkers(l_marks);
                var js = {
                    "id": l_agr[0].id, 
                    "cluster": mc
                };
                wgutil.l_MarkerClusterer[wgutil.l_MarkerClusterer.length] = js;
            }
        } else {
            wgutil.est_gru = false;
            for (var c = 0; c < wgutil.l_MarkerClusterer.length; c++) {
                wgutil.l_MarkerClusterer[c].cluster.clearMarkers();
            }
            if(wgutil.navIE8 == -1) var eyes = document.getElementById("tb_agrupamientos").getElementsByClassName("eye");
            else var eyes = getElementsByClassName("eye", "*", document.getElementById("tb_agrupamientos"));
            for (var i = 0; i < eyes.length; i++) {
                eyes[i].onclick();
                eyes[i].onclick();
            }
        }
    }

    this.cambiar_img = function (tipo) {
        var id_arcadj_mostrar;
        var index_seleccionado;
        if (tipo == "back") {
            if (this.img_selected == 0) {
                id_arcadj_mostrar = this.l_img[this.l_img.length - 1].id_arcadj;
                index_seleccionado = this.l_img.length - 1;
            } else {
                id_arcadj_mostrar = this.l_img[this.img_selected - 1].id_arcadj;
                index_seleccionado = this.img_selected - 1;
            }
        } else if (tipo == "next") {
            if (this.img_selected == this.l_img.length - 1) {
                id_arcadj_mostrar = this.l_img[0].id_arcadj;
                index_seleccionado = 0;
            } else {
                id_arcadj_mostrar = this.l_img[this.img_selected + 1].id_arcadj;
                index_seleccionado = this.mg_selected + 1;
            }
        }

        document.getElementById("img_" + this.l_img[img_selected].id_arcadj).style.display = "none";
        document.getElementById("img_" + id_arcadj_mostrar).style.display = "block";
        this.img_selected = index_seleccionado;
    }

    this.ocultar_imagenes = function(){
        document.getElementById("modalDialogPageBackground").style.display = "none";
        document.getElementById("slider").style.display = "none";
    }

    this.ocultarVacios = function (id_frawor, node) {
        //                limpiar_clusters();
        //                l_MarkerClusterer = [];
        var ocultar_vacios = false;
        if (node.checked)
            ocultar_vacios = true;
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + id_frawor + "&ocultar_vacios=" + ocultar_vacios);
        document.getElementById("layer_control").innerHTML = js;
    //                mostrar_all_markers(id_frawor);
    }

    this.tipo_vista_detalle = function(tip) {
        //                marker_select.setIcon("../img/gps/markers/" + marker_select.no_colore + "_" + size_marker + ".png");
        wgutil.marker_select.setAnimation(null);
        if (tip == 'L') {
            wgutil.infowindow.setContent(" ");
            wgutil.infowindow.open(null);
        } else if (tip == 'I') {
            document.getElementById("point_description").style.display = "none";
            wgutil.pestado = false;
        }
    }

    this.control_descripcion =function(event) {
        wgutil.infowindow.setContent(" ");
        wgutil.infowindow.open(null);
        document.getElementById("point_description").style.display = "none";
        wgutil.pestado = false;
        //                marker_select.setIcon("../img/gps/markers/" + marker_select.no_colore + "_" + size_marker + ".png");
        wgutil.marker_select.setAnimation(null);
    }

    this.actualizar_puntos_visibles = function() {
        var puntos = 0;
        for (var i = 0; i < this.g_markers.length; i++) {
            if (this.g_markers[i].getMap() != null){
                puntos++;
            }
        }
        document.getElementById("main_footer_puntos_visibles").innerHTML = puntos;
    }

    this.seleccionar_puntos = function (id_frawor) {
        this.drawing_manager.setMap(this.map);
        js = gettextfromurl(new getXMLObject(), "seleccion_include.jsp?id_frawor=" + id_frawor);
        document.getElementById("layer_control").innerHTML = js;
        google.maps.event.addListener(this.drawing_manager, 'rectanglecomplete', function(event) {
            for (var i = 0; i < wgutil.g_markers.length; i++) {
                if (wgutil.g_markers[i].getMap() != null && event.getBounds().contains(wgutil.g_markers[i].getPosition())) {
                    var existe = false;
                    for (var j = 0; j < wgutil.l_marker_select.length; j++) {
                        if (wgutil.l_marker_select[j].id == wgutil.g_markers[i].id) {
                            existe = true;
                            break;
                        }
                    }
                    if (!existe) {
                        wgutil.l_marker_select[wgutil.l_marker_select.length] = wgutil.g_markers[i];
                        wgutil.g_markers[i].setAnimation(google.maps.Animation.BOUNCE);
                    }

                }
            }
            event.setVisible(false);
            document.getElementById("puntos_seleccionados").innerHTML = wgutil.l_marker_select.length;
        });
        this.modo_seleccion = true;
    }

    this.cerrar_seleccion = function(id_frawor) {
        this.drawing_manager.setMap(null);
        this.l_marker_select = [];
        for (var i = 0; i < this.g_markers.length; i++) {
            this.g_markers[i].setAnimation(null);
        }
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor);
        document.getElementById("layer_control").innerHTML = js;
        this.modo_seleccion = false;
        
    }

    this.crear_portafolio_seleccion = function(id_frawor) {
        var nu_geocaps = "";
        for (var i = 0; i < this.l_marker_select.length; i++) {
            if (i == this.l_marker_select.length - 1) {
                nu_geocaps = nu_geocaps + this.l_marker_select[i].id;
            } else {
                nu_geocaps = nu_geocaps + this.l_marker_select[i].id + "_";
            }
        }
        this.limpiar_markers();
        this.limpiar_clusters();
        this.l_MarkerClusterer = [];
        this.drawing_manager.setMap(null);
        l_marker_select = [];
        js = gettextfromurl(new getXMLObject(), "filtro_include.jsp?id_frawor=" + this.id_frawor + "&l_puntos_selec=" + nu_geocaps + "&portafolio=true");
        document.getElementById("layer_control").innerHTML = js;
        this.mostrar_all_markers(this.id_frawor);
        this.modo_seleccion = false;
    }

    this.cambiar_modo_drawing_manager = function(modo, node, context_path) {
        if (modo == "hand") {
            this.drawing_manager.setDrawingMode(null);
            document.getElementById("modo_seleccion_hand_img").src = context_path+"/img/gps/hand_on.png";
            document.getElementById("modo_seleccion_rectangle_img").src = context_path+"/img/gps/rectangle_off.png";
        } else {
            this.drawing_manager.setDrawingMode(google.maps.drawing.OverlayType.RECTANGLE);
            document.getElementById("modo_seleccion_hand_img").src = context_path+"/img/gps/hand_off.png";
            document.getElementById("modo_seleccion_rectangle_img").src = context_path+"/img/gps/rectangle_on.png";
        }
    }

    this.deseleccionar_todos = function() {
        for (var i = 0; i < this.l_marker_select.length; i++) {
            this.l_marker_select[i].setAnimation(null);
        }
        this.l_marker_select = [];
        document.getElementById("puntos_seleccionados").innerHTML = this.l_marker_select.length;
    }

    this.grabar = function() {
        gettextfromurl_asinc(new getXMLObject(), "../wgp?xact=10&id_frawor=" + this.id_frawor);
    }
    
    this.mzoon_changed = function(){
        console.log("-->"+wgutil);
        console.log("-->"+wgutil.map);
        console.log("------------->");
        //            console.log("-->"+this.map);
        //            console.log("-->"+this.map.getZoom());
        switch(wgutil.map.getZoom()){
            case 0:{
                wgutil.g_markers_change_size('0.05');
                wgutil.size_marker = '0.05';
                break;
            }
            case 1:{
                wgutil.g_markers_change_size('0.10');
                wgutil.size_marker = '0.10';
                break;
            }
            case 2:{
                wgutil.g_markers_change_size('0.12');
                wgutil.size_marker = '0.12';
                break;
            }
            case 3:{
                wgutil.g_markers_change_size('0.13');
                wgutil.size_marker = '0.13';
                break;
            }
            case 4:{
                wgutil.g_markers_change_size('0.14');
                wgutil.size_marker = '0.14';
                break;
            }
            case 5:{
                wgutil.g_markers_change_size('0.15');
                wgutil.size_marker = '0.15';
                break;
            }
            case 6:{
                wgutil.g_markers_change_size('0.16');
                wgutil.size_marker = '0.16';
                break;
            }
            case 7:{
                wgutil.g_markers_change_size('0.17');
                wgutil.size_marker = '0.17';
                break;
            }
            case 8:{
                wgutil.g_markers_change_size('0.18');
                wgutil.size_marker = '0.18';
                break;
            }
            case 9:{
                wgutil.g_markers_change_size('0.19');
                wgutil.size_marker = '0.19';
                break;
            }
            case 10:{
                wgutil.g_markers_change_size('0.20');
                wgutil.size_marker = '0.20';
                break;
            }
            case 11:{
                wgutil.g_markers_change_size('0.25');
                wgutil.size_marker = '0.25';
                break;
            }
            case 12:{
                wgutil.g_markers_change_size('0.30');
                wgutil.size_marker = '0.30';
                break;
            }
            case 13:{
                wgutil.g_markers_change_size('0.40');
                wgutil.size_marker = '0.40';
                break;
            }
            case 14:{
                wgutil.g_markers_change_size('0.42');
                wgutil.size_marker = '0.42';
                break;
            }
            case 15:{
                wgutil.g_markers_change_size('0.44');
                wgutil.size_marker = '0.44';
                break;
            }
            case 16:{
                wgutil.g_markers_change_size('0.46');
                wgutil.size_marker = '0.46';
                break;
            }
            case 17:{
                wgutil.g_markers_change_size('0.48');
                wgutil.size_marker = '0.48';
                break;
            }
            case 18:{
                wgutil.g_markers_change_size('0.50');
                wgutil.size_marker = '0.50';
                break;
            }
            case 19:{
                wgutil.g_markers_change_size('0.52');
                wgutil.size_marker = '0.52';
                break;
            }
            case 20:{
                wgutil.g_markers_change_size('0.54');
                wgutil.size_marker = '0.54';
                break;
            }
            case 21:{
                wgutil.g_markers_change_size('0.56');
                wgutil.size_marker = '0.56';
                break;
            }
        }
    }
    
    //------------------------------------------------------------------------------------------------------------
    /*
	Metodos para usar "getElementsByClassName en IE8...
*/
    var getElementsByClassName = function (className, tag, elm){
        if (document.getElementsByClassName) {
            getElementsByClassName = function (className, tag, elm) {
                elm = elm || document;
                var elements = elm.getElementsByClassName(className),
                nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
                returnElements = [],
                current;
                for(var i=0, il=elements.length; i<il; i+=1){
                    current = elements[i];
                    if(!nodeName || nodeName.test(current.nodeName)) {
                        returnElements.push(current);
                    }
                }
                return returnElements;
            };
        }
        else if (document.evaluate) {
            getElementsByClassName = function (className, tag, elm) {
                tag = tag || "*";
                elm = elm || document;
                var classes = className.split(" "),
                classesToCheck = "",
                xhtmlNamespace = "http://www.w3.org/1999/xhtml",
                namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
                returnElements = [],
                elements,
                node;
                for(var j=0, jl=classes.length; j<jl; j+=1){
                    classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
                }
                try	{
                    elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
                }
                catch (e) {
                    elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
                }
                while ((node = elements.iterateNext())) {
                    returnElements.push(node);
                }
                return returnElements;
            };
        }
        else {
            getElementsByClassName = function (className, tag, elm) {
                tag = tag || "*";
                elm = elm || document;
                var classes = className.split(" "),
                classesToCheck = [],
                elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
                current,
                returnElements = [],
                match;
                for(var k=0, kl=classes.length; k<kl; k+=1){
                    classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
                }
                for(var l=0, ll=elements.length; l<ll; l+=1){
                    current = elements[l];
                    match = false;
                    for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
                        match = classesToCheck[m].test(current.className);
                        if (!match) {
                            break;
                        }
                    }
                    if (match) {
                        returnElements.push(current);
                    }
                }
                return returnElements;
            };
        }
        return getElementsByClassName(className, tag, elm);
    };
//---------------------------------------------------------------------------------------------------------------
}









